import { createRouter, createWebHashHistory } from 'vue-router'
import { Session } from '../api/storage.ts';
import { constantRoute } from './routes'
import {ElMessageBox} from "element-plus";

// 创建路由器
const router = createRouter({
  history: createWebHashHistory(),
  routes: constantRoute,
  scrollBehavior() {
    return {
      top: 0,
      left: 0
    }
  }
})
router.beforeEach( (to, from, next) => {
  if(to.path !== '/login' && to.path !== '/sign_in'){
    if(Session.get('token')){
      next()
    } else {
      ElMessageBox.alert('Вы еще не зарегистрировались', 'предъявлять', {}).then(() => {})
      next('/login')
    }
  } else {
    next()
  }


});

export default router
